package com.basic.business.print.service.impl;

import com.basic.business.common.constants.Constants;
import com.basic.business.common.redis.RedisCacheUtils;
import com.basic.business.print.mapper.ITOrdersPrintMapper;
import com.basic.business.print.service.ITOrdersPrintService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * 订单印刷品表服务实现类
 *
 * @author zhaoxy_jn@163.com
 */
@Service
public class TOrdersPrintServiceImpl implements ITOrdersPrintService {

    @Resource
    private ITOrdersPrintMapper ordersPrintMapper;

    /**
     * 项目启动时，初始化印刷品编码缓存
     */
    @PostConstruct
    public void init(){
        resetPrintCache();
    }

    @Override
    public List<String> getNormalPrintCode() {
        return ordersPrintMapper.getNormalPrintCode();
    }

    /**
     * 重置印刷品缓存
     */
    public void resetPrintCache(){
        // 清空缓存
        RedisCacheUtils.clearCache(Constants.PRINTS_REDIS_KEY + "*");
        // 加载缓存
        RedisCacheUtils.setCacheObject(Constants.PRINTS_REDIS_KEY, getNormalPrintCode());
    }
}
